/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package encaps.utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;


public class DatabaseUtil {
    private DatabaseUtil() {
    }

    public static void closeConnection(Connection conn, PreparedStatement ps) {
        try {
            if(conn != null) {
                conn.close();
            }
        } catch(SQLException e) {
        }
        try {
            if(ps != null) {
                ps.close();
            }
        } catch(SQLException e) {
        }
    }

    public static DataSource getDataSource() throws NamingException {
        Context namingContext = new InitialContext();
        return (DataSource) namingContext.lookup("jdbc/mySQLConnectionPool");
    }

    public static DataSource getDataSource(String dataSourceName) throws NamingException {
        Context namingContext = new InitialContext();
        return (DataSource) namingContext.lookup(dataSourceName);
    }
}
